<?php
    session_start();
    require_once '../model/userDao.php';
    if($_SERVER['REQUEST_METHOD']==='POST'){
        $uname=$_POST['username'];
        $upass=$_POST['password'];
        $head=$_POST['head'];
        $gender=$_POST['gender'];
        $uid=$_POST['uid'];
        if(isset($_FILES['avatar'])){
            echo "上传头像";
            $head=headUpload($_FILES['avatar']);
        }else{
            echo '没有头像';
        }
        echo $uname.','.$upass.','.$head.','.$gender.','.$uid;
        edit_user($uid,$uname, $upass, $head, $gender);
        $_SESSION['head']=$head;
        $_SESSION['username'] = $uname;
    }else{
        header("location:../views/error.php?msg=非法访问");
    }

    function headUpload($head){
    //图片暂存路径
    $headimgTmpName = $head["tmp_name"];
    //图片保存路径
    $headimgDestination=time() . uniqid() . $head["name"];
    if (move_uploaded_file($headimgTmpName, "../image/head/" . $headimgDestination)) {
            return $headimgDestination;
        } else {
                header('location:../views/error.php?msg=头像上传失败');
                die();
        }
}
?>